//
//  ImageScanCVCell.m
//  Mtime
//
//  Created by Mac on 15/8/10.
//  Copyright (c) 2015年 wxk. All rights reserved.
//

#import "ImageScanCVCell.h"

@implementation ImageScanCVCell
{

    UIScrollView *_scrollView;
    
    UIImageView *_imageView;

}
- (id)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {
        
        [self creatSubviews];

        
        [self creatGesture];
    }

    return self;
}

- (void)setImageName:(NSString *)imageName {

    _imageName = imageName;
    
    [_imageView setImageWithURL:[NSURL URLWithString:imageName]];

}


- (void)creatSubviews {

    _scrollView = [[UIScrollView alloc] initWithFrame:self.contentView.bounds];
    
    _scrollView.delegate = self;
    
    //设置_scrollView的最大最小放大比例
    _scrollView.minimumZoomScale = 1;
    _scrollView.maximumZoomScale = 1.5 ;
    
    [self.contentView addSubview:_scrollView];
    
    _imageView = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
    
    
    //设置_imageView响应点击事件
    _imageView.userInteractionEnabled = YES;
    
    //设置图片的填充属性
    _imageView.contentMode =UIViewContentModeScaleAspectFit;
    
    [_scrollView addSubview:_imageView];
    
    

    
}

- (void)creatGesture {

    UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    
    //设置点击的此时
    tapTwice.numberOfTapsRequired = 2;
    
    [_imageView addGestureRecognizer:tapTwice];
    
    
    UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureAction:)];
    
    //设置点击的此时
    tapOnce.numberOfTapsRequired = 1;
    
    [_imageView addGestureRecognizer:tapOnce];


    //设置单击手势的优先级低于双击手势  避免手势冲突
    [tapOnce requireGestureRecognizerToFail:tapTwice];
    
}

- (void)tapGestureAction:(UITapGestureRecognizer *)tap {

    if (tap.numberOfTapsRequired == 1.5) {
        
        if (_scrollView.zoomScale == 1.0) {
            
            [_scrollView setZoomScale:1.5 animated:YES];
        }else {
            
            [_scrollView setZoomScale:1.0 animated:YES];
        }
        
    }else {
        
        UINavigationBar *bar = self.viewController.navigationController.navigationBar;
        
        [self.viewController.navigationController setNavigationBarHidden:!bar.hidden animated:YES];
    }
}


//返回一个视图随UIScrollView等比例放大
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {

    return _imageView;
}

//回复初始状态  避免复用出现问题
- (void)bringScrollViewZoom {

    [_scrollView setZoomScale:1.0];

}

@end
